import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class ListOfPoints {
	private String[] colName;
	private Point[] list;
	private StopWatch stop;
	
	public ListOfPoints(int[] intList, String[] colName) {
		this.list = new Point[intList.length];
		for (int i = 0; i < intList.length; i++) {
			this.list[i] = new Point(intList[i]);
		}
		this.colName = colName;
		stop = new StopWatch();
	}
	
	public Point getPoint(int index) {
		return list[index];
	}
	
	/* return length of list */
	public int numberOfPoints() {
		return list.length;
	}
	
	public void setLocationOfList(DBCursor cursor) {
		while (cursor.hasNext()) {
			DBObject temp = cursor.next();
			setLocation((Integer) temp.get(colName[0]),
							(Double) temp.get(colName[1]),
							(Double) temp.get(colName[2]));
		//	System.out.println(stop.getElapsedTime());
		}
		setListToFalse();
	}
	
	public void printList() {
		for (int i = 0; i < numberOfPoints(); i++) {
			System.out.println("Point: " + list[i].getId() + " has Latitude " + list[i].getLatitude() + " and Longtitude " + list[i].getLongtitude());
		}
	}
	
	private void setListToFalse() {
		for (int i = 0; i < numberOfPoints(); i++) {
			list[i].setChanged(false);
		}
	}
	
	/* set location of point by index */
	public void setLocation(int index, double latitude, double longtitude) {
		for (int i = 0 ; i < numberOfPoints(); i++) {
			if (list[i].getId() == index) {
				list[i].setLatitude(latitude);
				list[i].setLongtitude(longtitude);
				list[i].setChanged(true);
				break;
			}
		}
	}
}


class Point {
	private boolean changed;
	private double latitude;
	private double longtitude;
	private int id;
	
	public Point(int id) {
		this.id = id;
		changed = false;
	}
	
	public boolean isChanged() {
		return changed;
	}

	public void setChanged(boolean changed) {
		this.changed = changed;
	}

	public double getLatitude() {
		return latitude;
	}
	
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	
	public double getLongtitude() {
		return longtitude;
	}
	
	public void setLongtitude(double longtitude) {
		this.longtitude = longtitude;
	}
	
	public int getId() {
		return id;
	}
	
}